<script src="http://www.html5canvastutorials.com/libraries/Three.js">
</script>
<script>
    window.requestAnimFrame = (function(callback){
        return window.requestAnimationFrame ||
        window.webkitRequestAnimationFrame ||
        window.mozRequestAnimationFrame ||
        window.oRequestAnimationFrame ||
        window.msRequestAnimationFrame ||
        function(callback){
            window.setTimeout(callback, 1000 / 60);
        };
    })();
 
    function animate(lastTime, angularSpeed, three){
        // update
        var date = new Date();
        var time = date.getTime();
        var timeDiff = time - lastTime;
        var angleChange = angularSpeed * timeDiff * 2 * Math.PI / 1000;
        three.cube.rotation.y += angleChange;
        lastTime = time;
 
        // render
        three.renderer.render(three.scene, three.camera);
 
        // request new frame
        requestAnimFrame(function(){
            animate(lastTime, angularSpeed, three);
        });
    }
 
    window.onload = function(){
        var angularSpeed = 0.2; // revolutions per second
        var lastTime = 0;
 
        // renderer
        var renderer = new THREE.WebGLRenderer();
        renderer.setSize(window.innerWidth, window.innerHeight);
        document.body.appendChild(renderer.domElement);
 
        // camera
        var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 1000);
        camera.position.z = 700;
 
        // scene
        var scene = new THREE.Scene();
 
        // material
        var material = new THREE.MeshLambertMaterial({
            //color: 0x0000ff
        });
 
        // cube
        var cube = new THREE.Mesh(new THREE.CubeGeometry(300, 300, 300), material);
        cube.overdraw = true;
        scene.add(cube);
 
        /*
         * add directional light source positioned
         * at x=1, y=0, z=0.  This will result in a directional
         * light source pointing in the negative x direction (to the left)
         * which cases the right side of the cube to be lightened
         * the left site of the cube to be darkened.
         */
        var directionalLight = new THREE.DirectionalLight(0xff0000);
        directionalLight.position.set(1, 0, 0).normalize();
        scene.add(directionalLight);
 
        // create wrapper object that contains three.js objects
        var three = {
            renderer: renderer,
            camera: camera,
            scene: scene,
            cube: cube
        };
 
        animate(lastTime, angularSpeed, three);
    };
</script>